package logic

import (
	"context"
	"encoding/json"

	"mail/service/account/api/internal/svc"
	"mail/service/account/api/internal/types"
	"mail/service/account/rpc/accountclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type ParticularLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewParticularLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ParticularLogic {
	return &ParticularLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ParticularLogic) Particular() (resp *types.ParticularResponse, err error) {
	// todo: add your logic here and delete this line
	uid, _ := l.ctx.Value("uid").(json.Number).Int64()
	res, err := l.svcCtx.AccountRpc.Particular(l.ctx, &accountclient.ParticularRequest{Id: uid})
	if err != nil {
		return nil, err
	}
	return &types.ParticularResponse{
		Id:     res.Id,
		Name:   res.Name,
		Gender: res.Gender,
		Mobile: res.Mobile,
	}, nil
}
